package com.chengzhi.eshopinventory.request;

import com.chengzhi.eshopinventory.entity.Inventory;
import com.chengzhi.eshopinventory.service.InventoryService;

/**
 * @description 库存更新操作
 * @author: ruanchengzhi
 * @create: 2021-04-01 16:47
 **/
public class InventoryQueryRequest implements BaseRequest {

    private InventoryService inventoryService;

    private Long inventoryId;

    private boolean forcedRefresh;


    public InventoryQueryRequest(InventoryService inventoryService, Long inventoryId, boolean forcedRefresh) {
        this.inventoryService = inventoryService;
        this.inventoryId = inventoryId;
        this.forcedRefresh = forcedRefresh;
    }

    /**
     * 查询库存数据放入缓存
     *
     * @param
     * @return void
     * @author ruanchengzhi
     * @date 2021/4/1
     */
    @Override
    public void execute() {
        Inventory inventory = inventoryService.getInventoryById(inventoryId);
        inventoryService.saveRedisInventory(inventory);
    }

    @Override
    public Long getInventoryId() {
        return inventoryId;
    }

    @Override
    public boolean isForcedRefresh() {
        return forcedRefresh;
    }
}
